package com.jiyi.activity.design;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jiyi.adapter.DividerItemDecoration;
import com.jiyi.adapter.recyclerview.CommonAdapter;
import com.jiyi.adapter.recyclerview.base.ViewHolder;
import com.jiyi.adapter.recyclerview.wrapper.EmptyWrapper;
import com.swift.maintenance.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * A simple {@link Fragment} subclass.
 */
public class TabFragment extends Fragment {
    List<String> childs = new ArrayList<>();
    EmptyWrapper adapter;

    @BindView(R.id.id_stickynavlayout_innerscrollview)
    RecyclerView rvView;
    LayoutInflater inflater;
    ViewGroup container;

    public TabFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_tab, null, false);
        ButterKnife.bind(this,view);
        this.inflater = inflater;
        this.container = container;
        int position = getArguments().getInt("position", 0);
        initItem();
        return view;
    }

    protected void initItem() {

        for (int i = 0; i < 100; i++) {
            childs.add(String.valueOf(i));
        }

        setAdapter();
    }


    private void setAdapter() {

        rvView.setLayoutManager(new LinearLayoutManager(getContext()));
        rvView.addItemDecoration(new DividerItemDecoration(getContext(),
                DividerItemDecoration.VERTICAL_LIST, getResources()
                .getDrawable(R.drawable.drvice_10)));

        CommonAdapter commonAdapter = new CommonAdapter(getContext(), R.layout.item_spinner, childs) {
            @Override
            protected void convert(ViewHolder holder, Object o, int position) {
                holder.setText(R.id.state_name, childs.get(position).toString());
            }
        };

        adapter = new EmptyWrapper(commonAdapter);

        View emptyView = inflater.inflate(R.layout.empty_view_text_and_image,
                container, false);
        ImageView ivEmptyTip = (ImageView) emptyView
                .findViewById(R.id.ivEmptyTip);
        TextView tvEmptyTip = (TextView) emptyView
                .findViewById(R.id.tvEmptyTip);
        ivEmptyTip.setImageResource(R.mipmap.tip_empty_huodong);
        tvEmptyTip.setText(R.string.NO_DATA);
        adapter.setEmptyView(emptyView);

        rvView.setAdapter(adapter);
        adapter.notifyDataSetChanged();

    }
}
